package com.zztl.infiniteBand.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.zztl.infiniteBand.BraceletApplication
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.model.BluetoothDeviceBean
import com.zztl.infiniteBand.util.device.DeviceUtil


/**
 * @desc
 * @auth ${user}
 * @time 2018/9/11  12:46
 */
class DeviceAdapter(layoutResId: Int, data: List<BluetoothDeviceBean>?) : BaseQuickAdapter<BluetoothDeviceBean, BaseViewHolder>(layoutResId, data) {

    override fun convert(helper: BaseViewHolder, item: BluetoothDeviceBean) {
        val watchBeanList = BraceletApplication.getmDaoSession()?.bindedWatchBeanDao?.loadAll()
        if (item.device?.name== null && watchBeanList!!.size > 0) {
            for (i in watchBeanList.indices) {
                if (item.device.device.address.equals(watchBeanList[i].mac)) {
                    helper.setText(R.id.tv_name, DeviceUtil.DEVICE_NAME )
                            .setText(R.id.tv_mac,item.device.device?.address)
                }
            }
        } else {
            helper.setText(R.id.tv_name, DeviceUtil.DEVICE_NAME)
                    .setText(R.id.tv_mac,item.device.device?.address)
        }
        helper.setVisible(R.id.tv_state, !item.isConnected && !item.isConnecting)
        helper.setVisible(R.id.iv_connect_success, item.isConnected)
        helper.setVisible(R.id.progress, item.isConnecting)

    }
}
